package com.heima.user.feign;

import com.heima.apis.user.IUserClient;
import com.heima.apis.wemedia.IWemediaClient;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.user.dtos.AuthDto;
import com.heima.model.user.pojos.ApUser;
import com.heima.model.user.pojos.ApUserRealname;
import com.heima.user.service.ApUserRealnameService;
import com.heima.user.service.ApUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/feign")
public class UserClient implements IUserClient {
    @Autowired
    private ApUserRealnameService apUserRealnameService;
    @Autowired
    private IWemediaClient wemediaClient;
    @Autowired
    private ApUserService apUserService;

    /**
     * 用户审核成功
     * @param dto
     */
    @PostMapping("/auth/authPass")
    @Override
    public void authPass(@RequestBody AuthDto dto) {
        String apUser = apUserRealnameService.auth(dto, ApUserRealname.Status.SUCCESS_AUTH.getCode());
        //创建自媒体账号
        wemediaClient.createWmUser(apUser);

    }

    /**
     * 用户审核失败
     * @param dto
     */
    @PostMapping("/auth/authFail")
    @Override
    public void authFail(@RequestBody AuthDto dto) {
        apUserRealnameService.auth(dto, ApUserRealname.Status.FAIL_AUTH.getCode());
    }

    /**
     * 用户审核--查询列表
     * @param dto
     * @return
     */
    @PostMapping("/auth/list")
    @Override
    public PageResponseResult findAuthList(@RequestBody AuthDto dto) {
        return apUserRealnameService.findList(dto);
    }

    @GetMapping("/user/get/{id}")
    @Override
    public ApUser findApUser(@PathVariable Integer id) {
        return apUserService.getById(id);
    }
}
